{% extends 'encyclopedia/base.html' %}

{% block title %}{% if object %}编辑相机{% else %}添加相机{% endif %} - 相机百科{% endblock %}

{% block content %}
    <div class="card">
        <div class="card-header bg-primary text-white">
            <h2 class="card-title">{% if object %}编辑相机：{{ object.title }}{% else %}添加新相机{% endif %}</h2>
        </div>
        <div class="card-body">
            <form method="post">
                {% csrf_token %}
                
                {% if form.errors %}
                    <div class="alert alert-danger" role="alert">
                        <strong>请修正以下错误：</strong>
                        <ul>
                            {% for field in form %}
                                {% for error in field.errors %}
                                    <li>{{ field.label }}: {{ error }}</li>
                                {% endfor %}
                            {% endfor %}
                            {% for error in form.non_field_errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    </div>
                {% endif %}
                
                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="mb-3">
                            {{ form.title.label_tag }}
                            {{ form.title }}
                            {% if form.title.help_text %}
                                <small class="form-text text-muted">{{ form.title.help_text }}</small>
                            {% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            {{ form.brand.label_tag }}
                            {{ form.brand }}
                            {% if form.brand.help_text %}
                                <small class="form-text text-muted">{{ form.brand.help_text }}</small>
                            {% endif %}
                        </div>
                    </div>
                </div>
                
                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="mb-3">
                            {{ form.category.label_tag }}
                            {{ form.category }}
                            {% if form.category.help_text %}
                                <small class="form-text text-muted">{{ form.category.help_text }}</small>
                            {% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            {{ form.release_date.label_tag }}
                            {{ form.release_date }}
                            {% if form.release_date.help_text %}
                                <small class="form-text text-muted">{{ form.release_date.help_text }}</small>
                            {% endif %}
                        </div>
                    </div>
                </div>
                
                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="mb-3">
                            {{ form.sensor_type.label_tag }}
                            {{ form.sensor_type }}
                            {% if form.sensor_type.help_text %}
                                <small class="form-text text-muted">{{ form.sensor_type.help_text }}</small>
                            {% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            {{ form.image_resolution.label_tag }}
                            {{ form.image_resolution }}
                            {% if form.image_resolution.help_text %}
                                <small class="form-text text-muted">{{ form.image_resolution.help_text }}</small>
                            {% endif %}
                        </div>
                    </div>
                </div>
                
                <div class="mb-3">
                    {{ form.content.label_tag }}
                    {{ form.content }}
                    {% if form.content.help_text %}
                        <small class="form-text text-muted">{{ form.content.help_text }}</small>
                    {% endif %}
                </div>
                
                <div class="d-flex justify-content-between">
                    <button type="submit" class="btn btn-primary">{% if object %}更新{% else %}保存{% endif %}</button>
                    <a href="{% url 'encyclopedia:camera_list' %}" class="btn btn-secondary">取消</a>
                </div>
            </form>
        </div>
    </div>
{% endblock %}